package jp.co.hcs.attendancemanagement.inputtableb.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.hcs.attendancemanagement.AMConstants;
import jp.co.hcs.attendancemanagement.action.AMAction;
import jp.co.hcs.attendancemanagement.inputtableb.actionform.InputTableBForm;
import jp.co.hcs.attendancemanagement.inputtableb.logic.InputTableBLogic;
import jp.co.hcs.attendancemanagement.inputtableb.logic.dto.EmployerInfoDTO;
import jp.co.hcs.attendancemanagement.util.StringUtil;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 * The Class InputTableBInitAction.
 */
public class InputTableBInitAction extends AMAction {

  public ActionForward executeImpl(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    String userId = (String) request.getSession().getAttribute(AMConstants.USER_LOGGED_IN);

    saveToken(request);
    InputTableBForm inputTableBForm = (InputTableBForm) form;
    inputTableBForm.resetInputFormData();
    inputTableBForm.setInputYear(StringUtil.getSystemYear());
    inputTableBForm.setInputMonth(StringUtil.getSystemMonth());
    InputTableBLogic inputTableBLogic = InputTableBLogic.getInstance();
    EmployerInfoDTO employerInfoDTO = inputTableBLogic.getEmployerInfo(userId);
    inputTableBForm.setEmployerCode(employerInfoDTO.getEmployerCode());
    inputTableBForm.setEmployerName(employerInfoDTO.getEmployerName());
    inputTableBForm.setDivisionName(employerInfoDTO.getDivisionName());
    inputTableBForm.setDepartmentName(employerInfoDTO.getDepartmentName());
    return mapping.findForward(SUCCESS);
  }

}
